{php include wl_template('common/header');}
<style type='text/css'>
	.trbody td {text-align: center; vertical-align:top;border-left:1px solid #ccc; border-bottom: 1px solid #ddd;}
	.order-rank img{width:16px; height:16px;}
	.js-remark,.js-admin-remark{word-break:break-all; overflow:hidden; background: #FDEEEE;color: #ED5050;padding: 5px 10px;}
	td.goods-info{position:relative; padding-left:60px;}
	.goods-info .img{position:absolute;top:50%; margin-top:-25px; background: url({IMAGE_LOADING}) center center no-repeat; width:50px;height:50px; }
	.goods-info span {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: block;}
	.status-text{cursor:pointer;}
	.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {border-top: 1px solid rgba(221, 221, 221, 0);}
	.col-md-1{padding-right: 0px;}
</style>
<div class="app-content">
	<ul class="nav nav-tabs">
		<li {if empty($_GPC['status'])}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist');}">全部{if $status0}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status0}</span>{/if}</a></li>
		<li {if $_GPC['status']==1}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>1));}">待核销{if $status1}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status1}</span>{/if}</a></li>
		<li {if $_GPC['status']==2}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>2));}">待评价{if $status2}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status2}</span>{/if}</a></li>
		<li {if $_GPC['status']==3}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>3));}">已完成{if $status3}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status3}</span>{/if}</a></li>
		<li {if $_GPC['status']==9}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>9));}">已过期{if $status9}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status9}</span>{/if}</a></li>
		<li {if $_GPC['status']==5}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>5));}">已取消{if $status5}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status5}</span>{/if}</a></li>
		<li {if $_GPC['status']==6}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>6));}">待退款{if $status6}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status6}</span>{/if}</a></li>
		<li {if $_GPC['status']==7}class="active"{/if}><a href="{php echo web_url('activity/activity_web/orderlist',array('status'=>7));}">已退款{if $status7}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status7}</span>{/if}</a></li>
	</ul>
	<div class="app-form">
		<div class="panel">
			<div class="panel-body">
				<form action="" method="get" class="form-horizontal" role="form" id="form1">
					<input type="hidden" name="c" value="site" />
					<input type="hidden" name="a" value="entry" />
					<input type="hidden" name="m" value="{MODULE_NAME}" />
					<input type="hidden" name="p" value="activity" />
					<input type="hidden" name="ac" value="activity_web" />
					<input type="hidden" name="do" value="orderlist" />
					<input type="hidden" name="status" value="{$_GPC['status']}" />
					<div class="form-group">
						<div class="col-md-2">
							<select name="keywordtype" class="form-control">
								<option value="">关键字类型</option>
								<option value="1" {if $_GPC['keywordtype']==1}selected="selected"{/if}>订单ID</option>
								<option value="2" {if $_GPC['keywordtype']==2}selected="selected"{/if}>订单编号</option>
								<option value="3" {if $_GPC['keywordtype']==3}selected="selected"{/if}>活动ID</option>
								<option value="4" {if $_GPC['keywordtype']==4}selected="selected"{/if}>商家ID</option>
								<option value="5" {if $_GPC['keywordtype']==5}selected="selected"{/if}>商家名称</option>
								<option value="6" {if $_GPC['keywordtype']==6}selected="selected"{/if}>买家昵称</option>
								<option value="7" {if $_GPC['keywordtype']==7}selected="selected"{/if}>买家手机</option>
								<option value="8" {if $_GPC['keywordtype']==8}selected="selected"{/if}>核销码</option>
							</select>
						</div>
						<button class="btn btn-default min-width" name="export" type="submit" value="export"><i class="fa fa-download"></i> 导出订单</button>
						<div class="col-sm-9 pull-right">
							<div class="input-group">
								<input type="text" name="keyword" class="form-control" value="{$_GPC['keyword']}"  placeholder="请输入关键字"/>
								<input type="hidden" name="activeid" value="{$_GPC['activeid']}" />
								<span class="input-group-addon" id="search">搜索</span>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div  class="app-table-list">
			<div class="order-list">
				<div class="panel-body table-responsive collapse in" id="order-template-item-4" style="padding: 0;">
					<table class="table table-bordered">
						<thead style="background-color: #FFFFFF;">
						<tr>
							<th style="width:50px">序号</th>
							<th style="width:220px;">商品</th>
							<th style="width:80px; text-align:center;">单价/数量</th>
							<th style="width:80px; text-align:center;">所属商家</th>
							<th style="width:220px; text-align:center;">买家</th>
							<th style="width:120px; text-align:center;">订单状态</th>
							<th style="width:130px; text-align:center;">金额</th>
						</tr>
						</thead>

					</table>
				</div>
				{loop $orders $y $item}
				<div class="panel panel-default">
					<div class="panel-heading clearfix" style="padding: 10px 15px;">
						<div class="pull-left">
							<span>订单号：{$item['orderno']}</span>
							{if $item['paytime'] }
							<span>||&nbsp;支付时间: {php echo date('Y-m-d', $item['paytime'])} {php echo date('H:i:s', $item['paytime'])} </span>
							{/if}
							{if $item['refundtime'] }
							<span>||&nbsp;退款时间: {php echo date('Y-m-d', $item['refundtime'])} {php echo date('H:i:s', $item['refundtime'])} </span>
							{/if}
						</div>
						<div class="pull-right">
							<span class="text-muted"></span>&nbsp;&nbsp;
							{if $item['usedtime']}
							<a href="javascript:;" class="lookhexiao" order-id="{$item['id']}">查看核销详情</a> -
							{/if}
							{if $item['status'] == 1 || $item['status'] == 9}
							<a href="javascript:;" class="js-refund" order-id="{$item['id']}">退款</a> -
							{/if}
							<a href="javascript:;" class="js-order-edit-remark" order-id="{$item['id']}">备注</a>
						</div>
					</div>
					<div class="panel-body table-responsive" style="padding: 0px;">
						<table class="table table-bordered">
							<tbody >
							<tr>
								<td style="width: 50px;" ><center>{php echo $y+1}</center></td>
								<td class="goods-info line-feed" style="width:220px;padding-left: 10px;">
									<div class="img"><img class="scrollLoading" src="{IMAGE_PIXEL}" data-url="{php echo tomedia($item['gimg'])}" height="50" width="50" onerror="this.src='{IMAGE_NOPIC_SMALL}'" ></div>
									<div class="title" style="padding-left: 60px;">
										<span>{$item['gname']}</span>
										{if $item['checkcode']}<span>核销码:{$item['checkcode']}</span>{/if}
									</div>
								</td>
								<td class="text-center" style="width:80px;">
									<p>￥{$item['price']}</p>
									<p>({$item['num']}人)</p>
								</td>
								<td class="text-center" style="width:80px;">{$item['merchantName']}</td>
								<td class="goods-info line-feed" style="width:220px;padding-left: 10px;">
									<div style="position: relative;top: 30px;left: 5px;" class="img"><img style="height: 100%;width: 100%;" class="scrollLoading" src="{IMAGE_PIXEL}" data-url="{php echo tomedia($item['headimg'])}"></div>
									<div class="title" style="padding-left: 60px;position: relative;top: -15px;">
										<span>{$item['nickname']}</span>
										<span>{$item['mobile']}</span>
									</div>
								</td>
								<td class="text-center" style="width:120px;">
									{if $item['status']==0}<span class="label label-danger">未支付</span>{/if}
									{if $item['status']==1}<span class="label label-warning">待使用</span>{/if}
									{if $item['status']==2}<span class="label label-success">待评价</span>{/if}
									{if $item['status']==3}<span class="label label-success">已完成</span>{/if}
									{if $item['status']==5}<span class="label label-success">已取消</span>{/if}
									{if $item['status']==6}<span class="label label-success">待退款</span>{/if}
									{if $item['status']==7}<span class="label label-success">已退款</span>{/if}
									{if $item['status']==9}<span class="label label-danger">已过期</span>{/if}
									{if $item['paytype']==1}<br><br><span class="label label-info">余额支付</span>{/if}
									{if $item['paytype']==2}<br><br><span class="label label-success">微信支付</span>{/if}
									{if $item['paytype']==3}<br><br><span class="label label-warning">支付宝</span>{/if}
									{if $item['paytype']==4}<br><br><span class="label label-danger">货到付款</span>{/if}
								</td>
								<td class="text-center" style="width:130px;">
									总额：{if empty($item['pay_price'])}{$item['price']}{else}{$item['pay_price']}{/if}<br>
									实付：{if $item['status'] == 5}0.00{else}{$item['price']}{/if}<br>
									{if $item['status']==1}
									<span class="label label-success js-bdelete" order-id="{$item['id']}">确认核销</span>
									{elseif $item['status']==2}<span class="label label-default js-cancleBdelete" order-id="{$item['id']}">取消核销</span>
									{elseif $item['status']==6}<span class="label label-danger js-refund" order-id="{$item['id']}">确认退款</span>
									{/if}
									{if $item['applyrefund']==1}
									<span class="label label-danger js-refund" order-id="{$item['id']}">确认退款</span>
									{/if}
								</td>
							</tr>
							</tbody>
						</table>
					</div>
					<div class="panel-footer js-admin-remark{$item['id']} js-admin-remark" order-id="{$item['id']}" {if empty($item['remark'])}style="display: none;"{/if} style="background-color:lightgoldenrodyellow">
					卖家备注：<span id="js-admin-remark{$item['id']}" style="">{$item['remark']}</span>
				</div>
			</div>
				{/loop}
				{$pager}
			</div>
		</div>
	</div>
	<div id="modal-module-gift" class="modal fade" tabindex="-1">
		<div class="modal-dialog" style='width: 920px;'>
			<div class="modal-content">
				<div class="modal-header">
					<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
					<h3>我的备注</h3></div>
				<div class="modal-body">
					<div class="modal-body">
						<textarea id="remark" name="admin_remark" class="form-control" rows="5"></textarea>
					</div>
				</div>
				<div class="modal-footer" style="padding: 5px 15px;">
					<a class="btn btn-default js-cancel" aria-hidden="true" data-dismiss="modal">取消</a>
					<a class="btn btn-primary js-order-remark-post" order-id="" data-dismiss="modal" aria-hidden="true">确定</a>
				</div>
			</div>
		</div>
	</div>
	<div id="modal-module-gift2" class="modal fade" tabindex="-1">
		<div class="modal-dialog" style='width: 620px;'>
			<div class="modal-content">
				<div class="modal-header">
					<button aria-hidden="true" data-dismiss="modal"  class="close" type="button">×</button>
					<h3>核销详情</h3>
				</div>
				<div class="modal-body">
					<div>剩余使用次数：<span id="lasttime">{{d.times}}</span></div>
					<div id="xiangq"></div>
				</div>
				<div class="modal-footer" style="padding: 5px 15px;">
					<a class="btn btn-primary js-order-remark-post" order-id=""  data-dismiss="modal" aria-hidden="true">确定</a>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#search").click(function(){
		$('#form1')[0].submit();
	});
</script>
<script type="text/javascript">
	require(['jquery', 'util'], function($, util){
		$('.js-copy').each(function(){
			var id=$(this).attr('data-id');
			util.clip($("#js-copy"+id), $(this).attr('data-url'));
		});
	});
</script>
<script type="text/javascript">
	$('#output').click(function(){
		var orderType = '{$_GPC['orderType']}';
		var status = '{$_GPC['status']}';
		var paytype = '{$_GPC['pay_type']}';
		var keywordtype = '{$_GPC['keywordtype']}';
		var keyword = '{$_GPC['keyword']}';
		var timetype = '{$_GPC['timetype']}';
		var times = "{$_GPC['time']['start']}";
		var timee = "{$_GPC['time']['end']}";
		location.href = "{php echo web_url('order/order/output')}&orderType="+orderType+"&status="+status+"&paytype="+paytype+"&keywordtype="+keywordtype+"&keyword="+keyword+"&timetype="+timetype+"&times="+times+"&timee="+timee;
	});
	$(function(){
		$('[name="rank_all"]').click(function() {
			var checked = this.checked;
			$('.js-rank').find('input:checkbox').each(function() {
				this.checked = checked;
			});
		});
		$('#export').click(function() {
			if ($('[name="selecttime[start]"]').val() == '') {
				alert('请选择下单时间');
				$(this).focus();
				return false;
			};
			$(this).attr('type', 'submit').submit();
		});
		
		$('.order-rank').each(function(){
			o.rank(this);
		});
		
		$('.js-order-status').delegate('.status-text', 'mouseover mouseout', function(event){
			var obj = this;
			if (event.type == 'mouseover'){
				var $pop = util.popover(obj, function($popover, obj) {obj.$popover = $popover;}, {html: '<span>'+$(obj).data('title')+'</span>', placement : 'top'});
			} else {
				this.$popover.remove();
			}
		});

		$('.js-order-status').delegate('.express', 'mouseover mouseout', function(event){
			var obj = this;
			if (event.type == 'mouseover'){
				var $pop = util.popover(obj, function($popover, obj) {obj.$popover = $popover;}, {html: '<p class="mb0">物流公司：'+$(obj).data('express')+'</p><p class="mb0">物流单号：'+$(obj).data('express-no')+'</p>', placement : 'top'});
			} else {
				this.$popover.remove();
			}
		});
		
		//查看核销详情
		$('.lookhexiao').click(function(){
		popwin = $('#modal-module-gift2').modal();
			var id = $(this).attr('order-id');
			$.post("{php echo web_url('activity/activity_web/hexiaotime')}",{id:id},function(d){
				if(!d.errno){
					$('#xiangq').html('');
					$('#lasttime').text(d.times);
					var len = d.data.length;
					if (len == 1) {
						var html = "<div>核销时间："+d.data[0].time+",核销方式："+d.data[0].typename+",核销人："+d.data[0].vername+"</div>";
						$("#xiangq").append(html);
					}else{
						for(var i=0;i<len;i++){
							var c = i+1;
							var html = "<div>第"+c+"次核销时间："+d.data[i].time+",核销方式："+d.data[i].typename+",核销人："+d.data[i].vername+"</div>";
							$("#xiangq").append(html);
						}	
					}
					
				}
			},"json");
			$('#double').hide();
		});
		
		// 修改备注
		$('.js-order-edit-remark').click(function(){
			var order_id = $(this).attr('order-id');
			var remarkvalue = $('#js-admin-remark'+order_id).text();
			$('.js-order-remark-post').attr("order-id",order_id);
			$('#remark').val(remarkvalue);
			popwin = $('#modal-module-gift').modal();
		});
		$('.js-cancel,.close').click(function() {
			$('#order-remark-container').hide();
			$('.main').css("opacity","1");$('.nav').css("opacity","1");$('.big-menu').css("opacity","1");
		});
		$('.js-order-remark-post').click(function() {
			var order_id = $(this).attr('order-id');
			var remark = $('#remark').val();
			$.post("{php echo web_url('activity/activity_web/remark')}",{id:order_id,remark:remark},function(d){
				if(!d.errno){
					$('#js-admin-remark'+order_id).html(remark);
					$('.js-admin-remark'+order_id).show();
				}
			},"json");
			$('#order-remark-container').hide();
			$('.main').css("opacity","1");$('.nav').css("opacity","1");$('.big-menu').css("opacity","1");
		});
		
		$('.js-bdelete').click(function(e) {
			e.stopPropagation();
			var _this = $(this).parent().parent().parent().parent().parent().parent();
			var order_id = $(this).attr('order-id');
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('activity/activity_web/confirmHexiao')}",{id:order_id},function(d){
				if(!d.errno){
					util.tips(d.message);
					location.reload();
				}
			},"json");
			}, {html: '确认核销?'});
			
		});
		$('.js-cancleBdelete').click(function(e) {
			e.stopPropagation();
			var _this = $(this).parent().parent().parent().parent().parent().parent();
			var order_id = $(this).attr('order-id');
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('activity/activity_web/cancleHexiao')}",{id:order_id},function(d){
				if(!d.errno){
					util.tips(d.message);
					location.reload();
				}
			},"json");
			}, {html: '确认取消核销?'});
			
		});
		$('.js-refund').click(function(e) {
			e.stopPropagation();
			var _this = $(this).parent().parent().parent().parent().parent().parent();
			var order_id = $(this).attr('order-id');
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('activity/activity_web/refundOrder')}",{id:order_id},function(d){
				if(!d.errno){
					_this.remove();
					util.tips('退款成功');
					location.reload();
				}else{
					alert('退款失败,原因是：'+d.message);
				}
			},"json");
			}, {html: '确认退款?'});
			
		});
		//删除
		$('.order-list').delegate('.js-remove', 'click', function(e){
			e.stopPropagation();
			var $this = $(this);
			var id = $this.attr('order-id');
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('rush/order/deleteOrder')}", { id : id }, function(data){
					if(!data.errno){
					$this.parent().parent().parent().remove();
					util.tips("删除成功！");
					};
				}, 'json');
			}, {html: '确认删除?'});
		});
		$('#de1').delegate('.js-delete','click',function(e){
			e.stopPropagation();
			var order_ids = [];
			var $checks=$('.checkbox:checkbox:checked');
			$checks.each(function() {
				if (this.checked) {
					order_ids.push(this.value);
				};
			});
				var $this = $(this);
				var ids = order_ids;
				util.nailConfirm(this, function(state) {
				if(!state) return;
					$.post("{php echo web_url('rush/order/deleteOrder')}", { ids : ids }, function(data){
						if(!data.errno){
						util.tips("删除成功！");
						location.reload();
						};
					}, 'json');
				}, {html: '确认删除?'});
			});
		});
</script>
{php include wl_template('common/footer');}